<html>
<head><meta charset="utf-8"><title>Nothrow trait functions · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Nothrow.20trait.20functions.html">Nothrow trait functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236034725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Nothrow%20trait%20functions/near/236034725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Nothrow.20trait.20functions.html#236034725">(Apr 25 2021 at 03:58)</a>:</h4>
<p>Related to: <span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/I.2FO.20safety/near/235994486">said</a>:</p>
<blockquote>
<p>I have a pair of traits in my chrono library, <code>TrivialClock</code> and <code>Monotonic</code>. Both are unsafe, and define the preconditions on implementations: <code>TrivialClock</code> states that if <code>T: TrivialClock</code>, then <code>&lt;T as Clock&gt;::now()</code> will not panic, ...</p>
</blockquote>
<p>Knowing what MIR looks like, it is obvious to me that the compiler would like to know when some functions don't throw, because then you don't have to generate a landing pad for the unwind. What would it take to support a general mechanism for declaring that functions can't throw? For concrete function implementations presumably the compiler already tries to figure this out, but for traits and function pointers this has to be attached to the type somehow. Perhaps an unsafe attribute, like in C++? It would be nice if implementing a no throw function in a trait is not unsafe provided that the compiler can prove that there is no unwind path.</p>



<a name="236059836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Nothrow%20trait%20functions/near/236059836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Nothrow.20trait.20functions.html#236059836">(Apr 25 2021 at 11:52)</a>:</h4>
<p>We have unwind(aborts) I think which isn't unsafe (iirc) and accomplishes almost this, but it's unstable and not really on a path towards stabilization, though I forget if there was an RFC for it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>